package router

import (
	"MyBlogv2/blog-common/middlewares"
	service "MyBlogv2/blog-single/service"
	"github.com/gin-gonic/gin"
)

func Router() *gin.Engine {
	r := gin.Default()
	r.Use(middlewares.CORSMiddleware())
	r.GET("/banners/list", service.GetBanners)

	public := r.Group("/public")
	{
		public.GET("/ask-code", service.SendCodeOfRegister)
	}
	banners := r.Group("/banners")
	{
		banners.POST("/upload/banner", middlewares.AuthPermission("blog:banner:add"), service.UploadBanner)
		banners.PUT("/update/sort/order", middlewares.AuthPermission("blog:banner:update"), service.UpdateSortOrder)
		banners.DELETE("/:id", middlewares.AuthPermission("blog:banner:delete"), service.DelBannerById)
		banners.GET("/back/list", middlewares.AuthPermission("blog:banner:list"), service.GetBanners4Admin)
	}
	user := r.Group("/user")
	{
		user.POST("/register", service.Register)
		user.POST("/login", service.Login)
		user.POST("/logout", service.Logout)
		user.GET("/auth/info", middlewares.AuthUserCheck(), service.GetUserInfo)
		user.POST("/auth/upload/avatar", middlewares.AuthUserCheck(), service.UpdateAvatar)
		user.POST("/auth/update", middlewares.AuthUserCheck(), service.UpdateUserInfo)
		user.GET("/list", middlewares.AuthPermission("system:user:list"), service.GetUserList)
		user.POST("/search", middlewares.AuthPermission("system:user:search"), service.SearchUserList)
		user.GET("/details/:id", middlewares.AuthPermission("system:user:details"), service.FindUserDetailById)
		user.DELETE("/delete", middlewares.AuthPermission("system:user:delete"), service.DeleteUserByIds)
		user.POST("/update/status", middlewares.AuthPermission("system:user:status:update"), service.UpdateUserStatus)
	}
	article := r.Group("/article")
	{
		article.GET("/recommend", service.GetRecommendList)
		article.GET("/list", service.GetArticlePageList)
		article.GET("/hot", service.GetHotArticleList)
		article.GET("/where/list/:typeId", service.GetArticleListByTypeId)
		article.GET("/detail/:id", service.GetArticleDetailById)
		article.GET("/visit/:id", service.UpdateVisitCount)
		article.GET("/related/:categoryId/:articleId", service.Related)
		article.GET("/random", service.GetRandomArticleList)
		article.GET("/search/init/title", service.InitSearchByTitle)
		article.GET("/search/by/content", service.SearchArticleByContent)
		article.GET("/timeLine", service.GetTimeLineList)
		article.POST("/upload/articleCover", middlewares.AuthPermission("blog:publish:article"), service.UploadArticleCover)
		article.POST("/publish", middlewares.AuthPermission("blog:publish:article"), service.PublishArticle)
		article.POST("/upload/articleImage", middlewares.AuthPermission("blog:publish:article"), service.UploadArticleImage)
		article.POST("/delete/articleCover", middlewares.AuthPermission("blog:publish:article"), service.DeleteArticleCover)
		article.GET("/back/list", middlewares.AuthPermission("blog:article:list"), service.GetArticleList)
		article.POST("/back/search", middlewares.AuthPermission("blog:article:search"), service.SearchArticle)
		article.POST("/back/update/status", middlewares.AuthPermission("blog:article:update"), service.UpdateArticleStatus)
		article.POST("/back/update/isTop", middlewares.AuthPermission("blog:article:update"), service.UpdateArticleIsTop)
		article.GET("/back/echo/:id", middlewares.AuthPermission("blog:article:echo"), service.GetArticleEcho)
		article.DELETE("/back/delete", middlewares.AuthPermission("blog:article:delete"), service.DeleteArticle)

	}
	comment := r.Group("/comment")
	{
		comment.POST("/auth/add/comment", middlewares.AuthUserCheck(), service.AddComment)
		comment.GET("/getComment", service.GetCommentList)
		comment.POST("/back/search", middlewares.AuthPermission("blog:comment:search"), service.SearchComment)
		comment.POST("/back/isCheck", middlewares.AuthPermission("blog:comment:isCheck"), service.UpdateCommentIsCheck)
		comment.GET("/back/list", middlewares.AuthPermission("blog:comment:list"), service.GetCommentList4Admin)
		comment.DELETE("/back/delete/:id", middlewares.AuthPermission("blog:comment:delete"), service.DeleteCommentById)
	}
	websiteInfo := r.Group("/websiteInfo")
	{
		websiteInfo.GET("/front", service.GetWebsiteInfo)
		websiteInfo.GET("", middlewares.AuthPermission("blog:get:websiteInfo"), service.GetWebsiteInfo)
		websiteInfo.POST("/upload/avatar", middlewares.AuthPermission("blog:update:websiteInfo"), service.UploadAvatar)
		websiteInfo.POST("/upload/background", middlewares.AuthPermission("blog:update:websiteInfo"), service.UploadBackground)
		websiteInfo.POST("/stationmaster", middlewares.AuthPermission("blog:update:websiteInfo"), service.UpdateStationmasterInfo)
		websiteInfo.POST("/webInfo", middlewares.AuthPermission("blog:update:websiteInfo"), service.UpdateWebsiteInfo)

	}
	like := r.Group("/like")
	{
		like.POST("/auth/like", middlewares.AuthUserCheck(), service.Like)
		like.DELETE("/auth/like", middlewares.AuthUserCheck(), service.CancelLike)
		like.GET("/whether/like", middlewares.AuthUserCheck(), service.IsLike)
	}
	link := r.Group("/link")
	{
		link.GET("/list", service.GetLinkList)
		link.POST("/auth/apply", middlewares.AuthUserCheck(), service.ApplyLink)
		link.GET("/back/list", middlewares.AuthPermission("blog:link:list"), service.GetBackLinkList)
		link.POST("back/search", middlewares.AuthPermission("blog:link:search"), service.SearchLink)
		link.POST("/back/isCheck", middlewares.AuthPermission("blog:link:isCheck"), service.UpdateLinkIsCheck)
		link.DELETE("/back/delete", middlewares.AuthPermission("blog:link:delete"), service.DeleteLink)
	}
	category := r.Group("/category")
	{
		category.GET("/list", service.GetCategoryList)
		category.POST("/back/search", middlewares.AuthPermission("blog:category:search"), service.SearchCategory)
		category.POST("/back/update", middlewares.AuthPermission("blog:category:update"), service.AddOrUpdateCategory)
		category.DELETE("/back/delete", middlewares.AuthPermission("blog:category:delete"), service.DeleteCategory)
		category.POST("/back/add", middlewares.AuthPermission("blog:category:add"), service.AddCategory)
		category.GET("/back/list", middlewares.AuthPermission("blog:category:list"), service.GetCategoryList4Admin)
		category.GET("/back/get/:id", middlewares.AuthPermission("blog:category:search"), service.GetCategoryById)
		category.PUT("", middlewares.AuthPermission("blog:category:add"), service.AddCategory4Category)
	}
	favorite := r.Group("/favorite")
	{
		favorite.POST("/auth/favorite", middlewares.AuthUserCheck(), service.Favorite)
		favorite.DELETE("/auth/favorite", middlewares.AuthUserCheck(), service.CancelFavorite)
		favorite.GET("/whether/favorite", middlewares.AuthUserCheck(), service.IsFavorite)
	}
	leaveWord := r.Group("/leaveWord")
	{
		leaveWord.GET("/list", middlewares.AuthUserCheck(), service.GetLeaveWordList)
		leaveWord.POST("/auth/userLeaveWord", middlewares.AuthUserCheck(), service.AddLeaveWord)
		leaveWord.GET("/back/list", middlewares.AuthPermission("blog:leaveword:list"), service.GetLeaveWordList4Admin)
		leaveWord.POST("/back/search", middlewares.AuthPermission("blog:leaveword:search"), service.SearchLeaveWord)
		leaveWord.DELETE("/back/delete", middlewares.AuthPermission("blog:leaveword:delete"), service.DeleteLeaveWord)
		leaveWord.POST("/back/isCheck", middlewares.AuthPermission("blog:leaveword:isCheck"), service.UpdateLeaveWordIsCheck)
	}
	tag := r.Group("/tag")
	{
		tag.GET("/list", service.GetTagList)
		tag.GET("/back/list", middlewares.AuthPermission("blog:tag:list"), service.GetArticleTagList)
		tag.POST("/back/search", middlewares.AuthPermission("blog:tag:search"), service.SearchTag)
		tag.GET("/back/get/:id", middlewares.AuthPermission("blog:tag:search"), service.GetTagById)
		tag.PUT("/back/add", middlewares.AuthPermission("blog:tag:add"), service.AddOrUpdateTag)
		tag.DELETE("/back/delete", middlewares.AuthPermission("blog:tag:delete"), service.DeleteTagByIds)
		tag.POST("/back/update", middlewares.AuthPermission("blog:tag:update"), service.AddOrUpdateTag)
		tag.PUT("", middlewares.AuthPermission("blog:tag:add"), service.AddTag4Article)

	}
	treeHole := r.Group("/treeHole")
	{
		treeHole.POST("/auth/addTreeHole", middlewares.AuthUserCheck(), service.AddTreeHole)
		treeHole.GET("/getTreeHoleList", service.GetTreeHoleList)
		treeHole.POST("/back/search", middlewares.AuthPermission("blog:treeHole:search"), service.SearchTreeHole)
		treeHole.POST("/back/isCheck", middlewares.AuthPermission("blog:treeHole:isCheck"), service.UpdateTreeHoleIsCheck)
		treeHole.GET("/back/list", middlewares.AuthPermission("blog:treeHole:list"), service.GetTreeHoleList4Admin)
		treeHole.DELETE("/back/delete", middlewares.AuthPermission("blog:treeHole:delete"), service.DeleteTreeHole)
	}
	menu := r.Group("/menu")
	{
		menu.GET("/router/list/:typeId", service.GetMenuList)
		menu.GET("/list/:typeId", middlewares.AuthPermission("system:menu:list"), service.GetMenuListByTypeId)
	}
	role := r.Group("/role")
	{
		role.GET("/list", middlewares.AuthPermission("system:role:list"), service.GetRoleList)
		role.POST("/update/status", middlewares.AuthPermission("system:role:status:update"), service.UpdateRoleStatus)
		role.PUT("/update", middlewares.AuthPermission("system:role:update"), service.UpdateRole)
		role.GET("/get/:id", middlewares.AuthPermission("system:role:get"), service.GetRoleById)
		role.POST("/search", middlewares.AuthPermission("system:role:search"), service.SearchRole)
		role.PUT("/add", middlewares.AuthPermission("system:role:add"), service.AddRole)
		role.DELETE("/delete", middlewares.AuthPermission("system:role:delete"), service.DeleteRoleByIds)
	}
	permission := r.Group("/permission")
	{
		permission.GET("/list", middlewares.AuthPermission("system:permission:list"), service.GetPermissionList)
		permission.GET("/search", middlewares.AuthPermission("system:permission:search"), service.SearchPermission)
		permission.GET("/menu", middlewares.AuthPermission("system:permission:menu:list"), service.GetPermissionMenuList)
		permission.POST("/add", middlewares.AuthPermission("system:permission:add"), service.AddOrUpdatePermission)
		permission.DELETE("/delete/:id", middlewares.AuthPermission("system:permission:delete"), service.DeletePermission)
		permission.GET("/get/:id", middlewares.AuthPermission("system:permission:get"), service.GetPermission)
		permission.POST("/update", middlewares.AuthPermission("system:permission:update"), service.AddOrUpdatePermission)

	}
	rolePermission := r.Group("/role/permission")
	{
		rolePermission.GET("/role/list", middlewares.AuthPermission("system:permission:role:list"), service.GetRoleHasPermission)
		rolePermission.GET("/not/role/list", middlewares.AuthPermission("system:permission:role:not:list"), service.GetRoleNoPermission)
		rolePermission.POST("/add", middlewares.AuthPermission("system:permission:role:add"), service.AddRolePermission)
		rolePermission.DELETE("/delete", middlewares.AuthPermission("system:permission:role:delete"), service.DeleteRolePermission)
	}
	userRole := r.Group("/user/role")
	{
		userRole.GET("/user/list", middlewares.AuthPermission("system:user:role:list"), service.GetUserHasRole)
		userRole.GET("/not/user/list", middlewares.AuthPermission("system:not:role:user:list"), service.GetUserNoRole)
		userRole.POST("/add", middlewares.AuthPermission("system:user:role:add"), service.AddUserRole)
		userRole.DELETE("/delete", middlewares.AuthPermission("system:user:role:delete"), service.DeleteUserRole)
		userRole.GET("/role/list", middlewares.AuthPermission("system:role:user:list"), service.GetRoleHasUser)
		userRole.GET("/not/role/list", middlewares.AuthPermission("system:user:role:not:list"), service.GetRoleNoUser)
	}

	return r
}
